<ion-view view-title="添加商品" show-tabs>

    <ion-content>
      <ion-list class="wrap-light2">
      <form name="addProductForm" ng-submit="add();">
        <ion-item class="margin-bottom-large item-icon-right" ng-click="selectProduct();" ng-if="false">
          从商品库选择
          <i class="icon ion-fork-repo dark2"></i>
        </ion-item>
        <ion-item class="item-select item-base">
          <span class="list-label">所属分类</span>
          <select ng-model="newProduct.catalogId" ng-change="getCatalogProperty();">
            <option ng-repeat="catalog in catalogs" value="{{catalog._id}}">{{catalog.name}}</option>
          </select>
        </ion-item>

        <ion-item class="item-input item-button-right">
          <span class="list-label">原厂条码</span>
          <input ng-model="newProduct.barcode" type="text" >
          <button type="button" class="button button-col icon-left ion-ios-barcode-outline" ng-click="scanBarcode()"> 扫码</button>
        </ion-item>
        <ion-item class="item-divider margin-top-large">
          预设价格
        </ion-item>
        <ion-item class="item-input">
          <span class="list-label">参考进价</span>
          <input ng-model="newProduct.cost_price" type="text" >
        </ion-item>
        <ion-item class="item-input">
          <span class="list-label">销售价格</span>
          <input ng-model="newProduct.cost_price" type="text" >
        </ion-item>
        <ion-item class="item-input">
          <span class="list-label">最低售价</span>
          <input ng-model="newProduct.cost_price" type="text" >
        </ion-item>
        <ion-item class="item-divider margin-top-large" ng-if="properties">
          商品属性
        </ion-item>
        <ion-item class="item-input" ng-repeat="(pl,property) in properties">
          <span class="list-label">{{property.name}}</span>
          <input type="hidden" ng-init="newProduct.properties[pl].name=property.name"/>
          <!-- 开新弹窗 -->
          <input type="text" ng-model="newProduct.properties[pl].value" ng-click="openModal(pl,property)" ng-if="property.field_type=='select'">
          <!-- 纯input  -->
          <input type="text" ng-model="newProduct.properties[pl].value" ng-if="property.field_type=='input'">

        </ion-item>
        <button class="button button-block button-royal" type="submit">确认添加</button>
        </form>
      </ion-list>
    </ion-content>
</ion-view>
